package com.huluobo.jetpackkotlindemo.paging.db

import androidx.room.Database
import androidx.room.Room
import androidx.room.RoomDatabase
import com.huluobo.jetpackkotlindemo.MyApplication

/**
 * Created by lc on 2022/12/21.
 */
@Database(entities = [RepoEntity::class], version = Constants.DB_VERSION)
abstract class AppDatabase : RoomDatabase() {
    abstract fun repoDao(): RepoDao

    companion object {
        val instance = AppDatabaseHolder.db
    }

    private object AppDatabaseHolder {
        val db: AppDatabase = Room.databaseBuilder(
            MyApplication.instance.applicationContext,
            AppDatabase::class.java,
            Constants.DB_NAME
        ).allowMainThreadQueries().build()
    }
}
